$(function () {
    var a = false, b = false;

    $("#stu_username_hide").blur(function () {
        var username = $("#stu_username_hide").val();
        if (username == "输入用户名") {
            $("#stu_username_hide").css("border", "1px solid red");
            $("#tips1").html("请输入用户名");
            $("#tips1").css("color", "red");
            $(".tipss1").show();
            a = false;
        } else {
            $("#stu_username_hide").css("border", "1px solid green");
            $(".tipss1").hide();
            a = true;
        }
    })

    $("#stu_password_hide").blur(function () {
        var password = $("#stu_password_hide").val();
        if (password == "输入密码") {
            $("#stu_password_hide").css("border", "1px solid red");
            $("#tips2").html("请输入密码!");
            $("#tips2").css("color", "red");
            $(".tipss2").show();
            b = false;
        } else {
            $("#stu_password_hide").css("border", "1px solid green");
            $(".tipss2").hide();
            b = true;
        }
    })


    $(".submit").click(function () {
        var username = $("#stu_username_hide").val();
        var password = $("#stu_password_hide").val();
        var type;



        if (a && b && username != "" && password != "") {
            if (validateCode()) {
                $.ajax({
                    type: "post",
                    url: "/login/userLogin",
                    dataType: "text",
                    data: {name: username, password: password},
                    success: function (result) {
                        if (result == 'success') {
                            //获取用户类型
                            $.ajax({
                                type: "post",
                                url: "/user/findUserTypeByName",
                                dataType: "text",
                                data: {uname:username},
                                success: function (result) {
                                    if (result != 'false') {
                                        type=result;
                                        console.log(result);
                                        if (type == "1") {
                                            window.location.href = "/mvoindex";
                                        } else if (type == "2") {
                                            window.location.href = "/bvoindex";
                                        } else {
                                            window.location.href = "/admin";
                                        }
                                    }
                                },
                                error: function () {
                                    alert("error");
                                }
                            });

                        } else {
                            alert("用户名或密码错误,请重新输入!");
                            $("#stu_username_hide").val("");
                            $("#stu_password_hide").val("");
                            $("#stu_username_hide").css("border", "1px solid red");
                            $("#stu_password_hide").css("border", "1px solid red");
                            createCode(4);
                        }
                    },
                    error: function () {
                        alert("error");
                    }
                })
            } else {
                alert("验证码错误!请重新输入");
                // createCode(4);
            }
        }
    })
})

